package com.avic.rong.goodsSort.adapter.drawerAdapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.goodsSort.bean.secondDrawerBean.GoodsSortGjDrawerOtherBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Chenjiaxin on 2019/7/15 20:22
 * E-Mail Address：16601203965@163.com
 * 使用时效
 */
public class GoodsSortGjDrawerUseTimeAdapter extends RecyclerView.Adapter<GoodsSortGjDrawerUseTimeAdapter.GoodsSortWdDrawerOtherViewHolder> {
    private Context context;
    private LayoutInflater inflater;
    private View view;
    //使用时效
    private List<GoodsSortGjDrawerOtherBean> useTimeList = new ArrayList<>();

    private GoodsSortGjDrawerUseTimeListener goodsSortGjDrawerUseTimeListener;

    public GoodsSortGjDrawerUseTimeListener getGoodsSortGjDrawerUseTimeListener() {
        return goodsSortGjDrawerUseTimeListener;
    }

    public void setGoodsSortGjDrawerUseTimeListener(GoodsSortGjDrawerUseTimeListener goodsSortGjDrawerUseTimeListener) {
        this.goodsSortGjDrawerUseTimeListener = goodsSortGjDrawerUseTimeListener;
    }

    public GoodsSortGjDrawerUseTimeAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setUseTimeList(List<GoodsSortGjDrawerOtherBean> useTimeList) {
        this.useTimeList = useTimeList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public GoodsSortWdDrawerOtherViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        view = inflater.inflate(R.layout.view_goods_rv_item1, viewGroup, false);
        return new GoodsSortWdDrawerOtherViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsSortWdDrawerOtherViewHolder holder, int i) {
        holder.tv.setText(useTimeList.get(i).getAttrValue());
        holder.tv.setSelected(useTimeList.get(i).isSelected());
        holder.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goodsSortGjDrawerUseTimeListener.setUseTimeSelected(i);
            }
        });
    }

    @Override
    public int getItemCount() {
        return useTimeList.size();
    }

    class GoodsSortWdDrawerOtherViewHolder extends RecyclerView.ViewHolder {
        TextView tv;

        public GoodsSortWdDrawerOtherViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.goods_Item_tv1);
        }
    }

    public interface GoodsSortGjDrawerUseTimeListener {
        void setUseTimeSelected(int index);
    }
}
